<style scoped>
.div_main{
  position: relative !important;
  background: transparent;
  padding-top: 10px;
  padding-bottom: 10px;
  padding-left: 10px;
  padding-right: 10px;
  overflow-y: scroll;
  height:calc(100% - 40px);
  /*border: 1px red solid;*/
}
.div_main::-webkit-scrollbar { width: 0; height: 0; }

.div_main_card{
  position: relative;
  left:0px;
  top:0px;
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 20px;
  border-radius: 10px;
  background-color: #ffffff;
  box-shadow: 0px 0px 2px rgba(0,37,57,0.2);
}
</style>
<template>
  <div class="div_main">
    <div style="position: relative;left:10px;top:40px;width: 68px;border-radius: 34px;overflow: hidden;z-index: 10000;">

      <img v-if="userInfo.ei_id!=null" :src='"/api/system/login/io/Viewer/biz_hrm_ei_basic_avatar/"+userInfo.ei_id+"?token="+userInfo.token'
           style="width: 68px;height: 68px;" />
      <img v-if="userInfo.ei_id==null" :src="userInfo.img_url"
           style="width: 68px;height: 68px;" />
    </div>
    <div class="div_main_card" style="font-size: 14px;color: #505968;">
      <div style="width: 100%;height: 42px;padding-top: 65px;font-size: 18px;padding-left: 12px;">
        {{userInfo.name}}
      </div>
      <div style="width: 100%;height: 42px;padding-left: 12px;">
        {{userInfo.org_name}}
      </div>
      <div style="width: 100%;height: 38px;padding-left: 12px;">
        {{userInfo.role_name}}
      </div>
      <van-button block plain type="danger" native-type="button" @click="logout"
                  style="height: 42px;font-size: 18px;color:#ffffff;background-color:#f46d6d;border-radius: 4px;border-color:#f46d6d;margin-top: 15px;">
        退出</van-button>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,

      userInfo:{
        'name':'',
        'org_name':'',
        'role_name':'',
        'ei_id':null,
        'img_url':'/images/mob-default-use-face.svg',
        'token':'--',
      },
    }
  },
  mounted() {
    this.v_getUserInfo();
  },
  methods: {
    async v_getUserInfo(){
      this.userInfo.name = elm.info.user.name;
      this.userInfo.org_name = '单位：'+elm.info.org.name;
      let role_name = '';
      for(let i=0;i<elm.info.role.length;i++){
        if(i>0){role_name = role_name+'、';}
        role_name = role_name+elm.info.role[i].name;
      }
      this.userInfo.role_name = '岗位：'+role_name;
      this.userInfo.token = elm.info.token;

      let imgCheck = await elm.post('/business/my/GetUserImg',{});
      console.log(JSON.stringify(imgCheck));
      if(imgCheck!=null && !this.em(imgCheck.id)){
        this.userInfo.ei_id= imgCheck.id;
      }
    },
    async logout(){
      let res = await elm.post('/system/login/Logout');
      if(res.status=="success")
      {
        //记录日志
        let oper_log = {};
        oper_log.oper_type = "1"; //手机
        oper_log.nick_name = elm.info.user.name;
        oper_log.menu_title = "/system/login/Logout";
        oper_log.oper_time = new Date().toLocaleString();
        oper_log.msg = "退出";
        await elm.post('/system/login/log/Upsert', oper_log);
        elm.info.token =null;
        elm.info.system =null;
        elm.info.menu =null;
        elm.info.user =null;
        elm.info.org =null;
        elm.info.role =null;
        //this.v("你已退出登录")
        setTimeout(()=>{
          top.location.href = elm.settings.routefix+elm.settings.loginPath;
        }, 1000);
      }
    },

    em: function (s) {
      if (s == null || s == '') { return true; }
      else { return false; }
    },

  }
}
</script>
